package org.vestbjergbyggecenter.Controller;

import java.util.ArrayList;

import org.vestbjergbyggecenter.Model.*;

public class OrderCtr {
	private OrderRecords orders;
	private CustomerRecords customers;
	private ProductRecords products;
	private EmployeeRecords employees;
	private static OrderCtr instance;
	
	private OrderCtr()
	{
		orders = OrderRecords.getInstance();
		customers = CustomerRecords.getInstance();
		products = ProductRecords.getInstance();
		employees = EmployeeRecords.getInstance();
	}
	
	public static OrderCtr getInstance()
	{
		if(instance==null)
		{
			instance=new OrderCtr();
		}
		return instance;		
	}
	
/*	public void createSubOrder(int orderId, int productId, int quantity)
	{
		SubOrder subOrder = new SubOrder(products.getProduct(productId), quantity);
		Order order = orders.getOrder(orderId);
		order.addSubOrder(subOrder);
	}*/
	public void addProduct(int productId, int orderId)
	{
		Product product = products.getProduct(productId);
		orders.getOrder(orderId).addProduct(product);
	}
	
	public void createOrder(int id, long deliveryDate, String status,
			int customerId, int salesAssistantId)
	{
		Customer customer = customers.getCustomer(customerId);
		SalesAssistant assistant = (SalesAssistant)employees.getEmployee(salesAssistantId);
		Order newOrder = new Order(id, deliveryDate, status, 
				customer, assistant);
		orders.addOrder(newOrder);
		customer.addOrder(newOrder);
		assistant.addMadeOrder(newOrder);
	}
	
	public Order getOrder(int id)
	{
		Order order = orders.getOrder(id);
		return order;
	}
	
	public ArrayList<Order> getOrders()
	{
		return orders.getOrders();		
	}
	
	public void updateOrder(int id, long deliveryDate, String status)
	{
		orders.updateOrder(id, deliveryDate, status);
	}
	
	public void deleteOrder(int id)
	{
		orders.removeOrder(id);
	}
	
	public void printOrder(int id)
    {
        Order order = getOrder(id);
        if (order != null)
            order.print();
    }
	
	public void listAllOrders()
    {
        orders.print();
    }	
}
